﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Math;

using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace Weazel.Math.Test
{
  [TestClass]
  public class TestSimpleAddition
  {
    [TestMethod]
    public void TestSingleFigureAddition_1()
    {
      Integer a = new Integer(8, 1, false);
      Assert.AreEqual("1", a.ToDecimalString());
      uint[] result = new uint[1];

      Integer.Add(ref result, a.Content, 1);

      Assert.AreEqual(2, (int)result[0]);
    }

    [TestMethod]
    public void TestSingleFigureAddition_2()
    {
      Integer a = new Integer(32, 0xFFFFFFFF, false);
      Assert.AreEqual("ffffffff", a.ToHexadecimalString());
      uint[] result = new uint[1];

      Integer.Add(ref result, a.Content, 1);

      Assert.AreEqual(0, (int)result[0]);
    }

    [TestMethod]
    public void TestSingleFigureAddition_3()
    {
      Integer a = new Integer(32, 0xFFFFFFFF, false);
      Assert.AreEqual("ffffffff", a.ToHexadecimalString());
      uint[] result = new uint[2];

      Integer.Add(ref result, a.Content, 1);

      Assert.AreEqual(0, (int)result[0]);
      Assert.AreEqual(1, (int)result[1]);
    }

    [TestMethod]
    public void TestMultiFigureAddition_1()
    {
      Integer a = new Integer(8, 1, false);
      Integer b = new Integer(8, 1, false);

      Assert.AreEqual("1", a.ToDecimalString());
      Assert.AreEqual("1", b.ToDecimalString());

      uint[] result = new uint[1];

      Integer.Add(ref result, a.Content, false, b.Content, false);

      Assert.AreEqual(2, (int)result[0]);
    }

    [TestMethod]
    public void TestMultiFigureAddition_2()
    {
      Integer a = new Integer(32, 0xFFFFFFFF, false);
      Integer b = new Integer(8, 1, false);

      Assert.AreEqual("ffffffff", a.ToHexadecimalString());
      Assert.AreEqual("1", b.ToDecimalString());

      uint[] result = new uint[1];

      Integer.Add(ref result, a.Content, false, b.Content, false);

      Assert.AreEqual(0, (int)result[0]);
    }

    [TestMethod]
    public void TestMultiFigureAddition_3()
    {
      Integer a = new Integer(32, 0xFFFFFFFF, false);
      Integer b = new Integer(8, 1, false);

      Assert.AreEqual("ffffffff", a.ToHexadecimalString());
      Assert.AreEqual("1", b.ToDecimalString());

      uint[] result = new uint[2];

      Integer.Add(ref result, a.Content, false, b.Content, false);

      Assert.AreEqual(0, (int)result[0]);
      Assert.AreEqual(1, (int)result[1]);
    }

    [TestMethod]
    public void TestMultiFigureAddition_4()
    {
      Integer a = new Integer(8, 1, false);
      Integer b = new Integer(32, 0xFFFFFFFF, false);

      Assert.AreEqual("1", a.ToDecimalString());
      Assert.AreEqual("ffffffff", b.ToHexadecimalString());

      uint[] result = new uint[2];

      Integer.Add(ref result, a.Content, false, b.Content, false);

      Assert.AreEqual(0, (int)result[0]);
      Assert.AreEqual(1, (int)result[1]);
    }

    [TestMethod]
    public void TestMultiFigureAddition_5()
    {
      Integer a = new Integer(64, 0x1010101010101010, false);
      Integer b = new Integer(64, 0x0101010101010101, false);

      Assert.AreEqual("1010101010101010", a.ToHexadecimalString());
      Assert.AreEqual("101010101010101", b.ToHexadecimalString());

      uint[] result = new uint[2];

      Integer.Add(ref result, a.Content, false, b.Content, false);

      Assert.AreEqual("11111111", string.Format("{0:X}", (int)result[0]));
      Assert.AreEqual("11111111", string.Format("{0:X}", (int)result[1]));
    }
  }
}
